package com.wuming.house.service.impl;

import com.wuming.house.dao.ActivityMapper;
import com.wuming.house.dao.DecorateMapper;
import com.wuming.house.model.Activity;
import com.wuming.house.model.Decorate;
import com.wuming.house.service.ActivityService;
import com.wuming.house.service.DecorateService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuhuai
 * @createTime 2019/8/27 19:01
 * @Description:
 */
@Service
public class ActivityServiceImpl extends BaseServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public List<Activity> getActivitiesByPage(String title, String source, int pageIndex, int pageSize) {
        Map<String,Object> params = new HashMap<>();
        if (StringUtils.isNotBlank(title)){
            params.put("title",title);
        }
        if (StringUtils.isNotBlank(source)){
            params.put("source",source);
        }
        try {
            return (List<Activity>) this.getPageList(ActivityMapper.class,"selectActivities",params,pageIndex,pageSize);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int getTotal(String title, String source) {
        Map<String,Object> params = new HashMap<>();
        if (StringUtils.isNotBlank(title)){
            params.put("title",title);
        }
        if (StringUtils.isNotBlank(source)){
            params.put("source",source);
        }
        try {
            return this.getTotal(ActivityMapper.class,"selectTotal",params);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public Activity getActivityById(Integer id) {
        try {
            return activityMapper.selectByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void saveActivity(Activity activity) {
        try {
            activityMapper.insert(activity);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void modifyActivity(Activity activity) {
        try {
            activityMapper.updateByPrimaryKey(activity);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void delete(Integer id) {
        try {
            activityMapper.deleteByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
